package ltd.hellotrik.common.util;


import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class UtilDateConverter{

	public Object convert(Class arg0, Object arg1) {

		if (arg1 instanceof Date) {
			return arg1;
		}
		if (arg1 instanceof String) {
			String p = (String) arg1;
			if (p == null || p.trim().length() == 0) {
				return null;
			}
			try {
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				return df.parse(p.trim());
			} catch (Exception e) {
				try {
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					return df.parse(p.trim());
				} catch (Exception ex) {
					return null;
				}
			}

		}
		return arg1;
	}
}
